package com.cat.yygh.hosp.controller.api;

import com.cat.yygh.hosp.bean.Result;
import com.cat.yygh.hosp.service.DepartmentService;
import com.cat.yygh.hosp.utils.HttpRequestHelper;
import com.cat.yygh.model.hosp.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp")
public class ApiDepartmentController {
    /*注入科室的服务层*/
    @Autowired
    private DepartmentService departmentService;
    @PostMapping("/department/list")
    public Result getDepartmentList(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        Page<Department> departmentPage = departmentService.getDepartmentPage(stringObjectMap);
        return Result.ok(departmentPage);
    }


    @PostMapping("/saveDepartment")
    public Result saveDepartment(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        departmentService.saveDepartment(stringObjectMap);
        return Result.ok();
    }
    @PostMapping("/department/remove")
    public Result removeDepartment(HttpServletRequest request){
        Map<String, Object> stringObjectMap = HttpRequestHelper.switchMap(request.getParameterMap());
        departmentService.removeDepartment(stringObjectMap);
        return Result.ok();
    }
}
